package com.sw.c.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sw.c.mapper.RoleDao;
import com.sw.c.pojo.entity.Role;
import com.sw.c.pojo.vo.RolePage;
import com.sw.c.service.RoleService;
import com.sw.c.utils.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 角色表(Role)表服务实现类
 *
 * @author makejava
 * @since 2024-04-16 12:31:45
 */
@Service("roleService")
@Transactional(rollbackFor = Exception.class)
@Slf4j
public class RoleServiceImpl extends ServiceImpl<RoleDao, Role> implements RoleService {
    @Resource
    private RoleDao roleDao;


    @Override
    public PageResult<Role> pageList(RolePage rolePage) {
        Page<Role> page = new Page<>(rolePage.getPageNum(), rolePage.getPageSize());
        IPage<Role> iPage = roleDao.getPageList(page,rolePage);

        PageResult pageResult = new PageResult();
        List<Role> records = iPage.getRecords();

        pageResult.setList(records);
        pageResult.setPages(iPage.getPages());
        pageResult.setTotal(iPage.getTotal());
        return pageResult;
    }

    @Override
    public void delRole(Integer id) {
        roleDao.delRole(id);
    }
}
